﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

using AwesomeEnginePC.Physics;
using AwesomeEnginePC.Graphics.TwoDimensional.Sprites;
using AwesomeEnginePC.Graphics.TwoDimensional.Text;

namespace AwesomeEnginePC.Graphics.TwoDimensional.Menus
{
    public enum MenuButtonStatus
    {
        NotSelected = 0,
        Hovering,
        Pressed,
    }

    public class MenuButton : MenuLabel
    {
        /* a button is just a 3 BaseSprites:
         * -normal (not selected)
         * -hover
         * -pressed in
         */

        private ContentManager _cm;

        private BaseSprite _notSelectedSprite;
        private BaseSprite _hoveringSprite;
        private BaseSprite _pressedSprite;

        //Add this later
        //Have code to Convert this into the above 3 using the one SpriteSheet
        private SpriteSheet _imageSheet;

        //Null = inactive
        //False = Hovering/Selected
        //True = Button has been pressed
		public bool? buttonPress
		{
			get;
			private set;
		}

        public override void Init()
        {
			ResetButton();
			_notSelectedSprite.Active = true;
			buttonPress = null;

			if(_displayText != null)
				_displayText.Active = true;
        }

		private void ResetButton()
		{
			_notSelectedSprite.Active = false;
			_hoveringSprite.Active = false;
			_pressedSprite.Active = false;
		}

        public void PressButton()
        {
			ResetButton();
			_pressedSprite.Active = true;
            buttonPress = true;
        }

        public void SelectButton()
        {
			ResetButton();
			_hoveringSprite.Active = true;
            buttonPress = false;
        }

		public void DeselectButton()
		{
			Init();
		}

        public override Vector<int> Position
        {
            get
            {
                return _notSelectedSprite.Position;
            }
            set
            {
                _notSelectedSprite.Position = value;
                _hoveringSprite.Position = value;
                _pressedSprite.Position = value;
				_displayText.Position = value;
            }
        }

        public override int Height
        {
            get
            {
                return _notSelectedSprite.Height;
            }
            set
            {
                _notSelectedSprite.Height = value;
                _hoveringSprite.Height = value;
                _pressedSprite.Height = value;
				_displayText.Height = value;
            }
        }

        public override int Width
        {
            get
            {
                return _notSelectedSprite.Width;
            }
            set
            {
                _notSelectedSprite.Width = value;
                _hoveringSprite.Width = value;
                _pressedSprite.Width = value;
				_displayText.Width = value;
            }
        }

        public MenuButton(ContentManager cm, string notSelectedAssetName, string hoveringAssetName, string pressedAssetName)
            :base(cm)
        {
            _cm = cm;
            _notSelectedSprite = new BaseSprite(_cm, notSelectedAssetName);
            _hoveringSprite = new BaseSprite(_cm, hoveringAssetName);
            _pressedSprite = new BaseSprite(_cm, pressedAssetName);
        }

        public MenuButton(ContentManager cm, BaseSprite notSelectedSprite, BaseSprite hoveringSprite, BaseSprite pressedSprite)
            :base(cm)
        {
            _cm = cm;
            _notSelectedSprite = notSelectedSprite;
            _hoveringSprite = hoveringSprite;
            _pressedSprite = pressedSprite;
        }

        public MenuButton(ContentManager cm, string notSelectedAssetName, string hoveringAssetName, string pressedAssetName, string spritefontAssetName, string text)
            :base(cm, spritefontAssetName, text)
        {
            _cm = cm;
            _notSelectedSprite = new BaseSprite(_cm, notSelectedAssetName);
            _hoveringSprite = new BaseSprite(_cm, hoveringAssetName);
            _pressedSprite = new BaseSprite(_cm, pressedAssetName);
        }

        public MenuButton(ContentManager cm, BaseSprite notSelectedSprite, BaseSprite hoveringSprite, BaseSprite pressedSprite, BaseString displayText)
            :base(cm, displayText)
        {
            _cm = cm;
            _notSelectedSprite = notSelectedSprite;
            _hoveringSprite = hoveringSprite;
            _pressedSprite = pressedSprite;
        }

        //Setup MenuButton using a SpriteSheet instead of 3 basesprites

		public override void Draw(GameTime gameTime, SpriteBatch SB)
		{
			//Background, then text
			_notSelectedSprite.Draw(gameTime, SB);
			_hoveringSprite.Draw(gameTime, SB);
			_pressedSprite.Draw(gameTime, SB);

			if (_displayText != null)
				_displayText.Draw(gameTime, SB);
		}
    }
}
